package com.site.service.impl;

import com.night.common.entity.logistical.Area;
import com.site.mapper.AreaMapper;
import com.site.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: AreaServiceImpl
 * @author: LJC
 * @date: 2022/10/20-10:54
 */
@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaMapper areaMapper;

    //获取所有场地信息
    @Override
    public List<Area> getAll() {

        return areaMapper.getAll();
    }

    //增加场地信息
    @Override
    public void addArea(Area area) {

    }

    //修改场地信息
    @Override
    public void updateArea(Area area) {
        areaMapper.updateArea(area);
    }

    //逻辑删除
    @Override
    public void delAreaById(Area area) {
        areaMapper.delAreaById(area);
    }

    //根据id查询场地信息
    @Override
    public Area getAreaById(Area area) {
        return areaMapper.getAreaById(area);
    }

    //根据场地类型查找
    @Override
    public List<Map<String, String>> getAreaByareaType(Area area) {
        //
        String areaDetail;
        List<Map<String, String>> list = new ArrayList<>();
        List<Area> arealist = areaMapper.getAreaByareaType(area);
        for (Area a : arealist) {
            Map<String, String> map = new HashMap<>();
            String areaPosition = a.getAreaPosition();
            Integer areaFloor = a.getAreaFloor();
            areaDetail = a.getAreaDetail();
            if (Integer.parseInt(areaDetail) <= 9){
                areaDetail = "0" + areaDetail;
            }
            String areaAddrs =areaPosition + areaFloor.toString() + "层" + areaDetail + "号";
            map.put("id",a.getId().toString());
            map.put("areaAddrs",areaAddrs);
            list.add(map);
        }
        return list;
    }
}
